<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<title>Exported from Notepad++</title>
<style type="text/css">
span {
	font-family: 'Courier New';
	font-size: 10pt;
	color: #000000;
}
.sc0 {
}
.sc2 {
	font-style: italic;
	color: #0000FF;
}
.sc4 {
	color: #8000FF;
}
.sc5 {
	font-weight: bold;
	font-style: italic;
	color: #0000FF;
}
.sc6 {
	font-weight: bold;
	color: #008000;
}
.sc8 {
	font-weight: bold;
	font-style: italic;
	color: #008000;
}
.sc10 {
	font-weight: bold;
	color: #0080FF;
}
.sc11 {
}
.sc14 {
	color: #8080FF;
}
</style>
</head>
<body>
<div style="float: left; white-space: pre; line-height: 1; background: #FFFFFF; "><span class="sc2">// ================================================== //</span><span class="sc0">
</span><span class="sc2">// ============ TUTORIELS BEBOP 1.0 ================= //</span><span class="sc0">
</span><span class="sc2">// ================================================== //</span><span class="sc0">

</span><span class="sc2">// Synthèse de circuit combinatoire avec bopbdd</span><span class="sc0">
</span><span class="sc2">// Exemple de génération d'image rom par un bloc externe avant synthèse</span><span class="sc0">

</span><span class="sc2">// Pour l'exemple, on illustre une division entière sur N bits</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc5">intargv</span><span class="sc0"> </span><span class="sc8">N</span><span class="sc0"> 

</span><span class="sc10">#</span><span class="sc6">init</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc10">&lt;-</span><span class="sc0"> </span><span class="sc11">a/b</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">div_fct</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc11">int_a</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0">
        </span><span class="sc5">if</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0">
        </span><span class="sc5">then</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">load_of_int</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">par</span><span class="sc0"> </span><span class="sc11">exemple</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">on</span><span class="sc0"> </span><span class="sc11">decide</span><span class="sc0"> </span><span class="sc11">de</span><span class="sc0"> </span><span class="sc11">mettre</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
</span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0">      </span><span class="sc5">then</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">load_of_iter</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">fun</span><span class="sc0"> </span><span class="sc11">_</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0"> </span><span class="sc8">Random</span><span class="sc10">.</span><span class="sc11">bool</span><span class="sc0"> </span><span class="sc10">())</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">non</span><span class="sc0"> </span><span class="sc11">specifiée</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
        </span><span class="sc5">else</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">load_of_int</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">int_a</span><span class="sc0"> </span><span class="sc11">/</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc10">);;</span><span class="sc0">
    
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">tmp_s</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Array</span><span class="sc10">.</span><span class="sc11">create</span><span class="sc0"> </span><span class="sc11">_N</span><span class="sc0"> </span><span class="sc11">false</span><span class="sc10">;;</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc2">// Une methode de test unitaire </span><span class="sc0">
</span><span class="sc10">#</span><span class="sc6">method</span><span class="sc0"> </span><span class="sc6">test</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">a</span><span class="sc10">:[</span><span class="sc8">N</span><span class="sc10">],</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc10">:[</span><span class="sc8">N</span><span class="sc10">],</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc8">N</span><span class="sc10">])</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">int_a</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_int</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_int</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
    </span><span class="sc11">div_fct</span><span class="sc0"> </span><span class="sc11">tmp_s</span><span class="sc0"> </span><span class="sc11">int_a</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc10">;</span><span class="sc0">
    </span><span class="sc5">if</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0">
    </span><span class="sc5">then</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">on</span><span class="sc0"> </span><span class="sc11">ne</span><span class="sc0"> </span><span class="sc11">teste</span><span class="sc0"> </span><span class="sc11">pas</span><span class="sc0"> </span><span class="sc11">la</span><span class="sc0"> </span><span class="sc11">sortie</span><span class="sc0"> </span><span class="sc11">non</span><span class="sc0"> </span><span class="sc11">specifiée</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc5">else</span><span class="sc0">
        </span><span class="sc5">for</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0"> </span><span class="sc5">to</span><span class="sc0"> </span><span class="sc11">pred</span><span class="sc0"> </span><span class="sc11">_N</span><span class="sc0"> </span><span class="sc5">do</span><span class="sc0">
            </span><span class="sc5">if</span><span class="sc0"> </span><span class="sc11">tmp_s</span><span class="sc10">.(</span><span class="sc11">i</span><span class="sc10">)</span><span class="sc0"> </span><span class="sc10">&lt;&gt;</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc10">.(</span><span class="sc11">i</span><span class="sc10">)</span><span class="sc0">
            </span><span class="sc5">then</span><span class="sc0"> </span><span class="sc11">raise</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc8">TEST_FAILURE</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">true</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc14">"Test div Failed"</span><span class="sc10">))</span><span class="sc0">
            </span><span class="sc5">else</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
        </span><span class="sc11">done</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc11">main</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">a</span><span class="sc10">:[</span><span class="sc8">N</span><span class="sc10">],</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc10">:[</span><span class="sc8">N</span><span class="sc10">])</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">adivb</span><span class="sc10">:[</span><span class="sc8">N</span><span class="sc10">]</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">int_a</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_int</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_int</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
    </span><span class="sc11">div_fct</span><span class="sc0"> </span><span class="sc11">adivb</span><span class="sc0"> </span><span class="sc11">int_a</span><span class="sc0"> </span><span class="sc11">int_b</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">
</span></div></body>
</html>
